package nowcode;

import java.util.ArrayList;

public class FindContinuousSequenceSolution {

    public static void main(String[] args) {
        FindContinuousSequenceSolution sequenceSolution = new FindContinuousSequenceSolution();
        sequenceSolution.FindContinuousSequence(9);
    }

    public ArrayList<ArrayList<Integer>> FindContinuousSequence(int sum) {

        ArrayList<ArrayList<Integer>> list = new ArrayList<>();
        if (sum <= 2) {
            return list;
        }
        int rightNum = (sum + 1) / 2;
        int startNum = 1;

        while (startNum < rightNum) {
            ArrayList<Integer> temp = new ArrayList<>();
            temp.add(startNum);
            int tempSum = startNum;
            for (int right = startNum + 1; right <= rightNum; right++) {
                temp.add(right);
                tempSum += right;
                if (tempSum == sum) {
                    list.add(temp);
                    break;
                } else if (tempSum > sum) {
                    break;
                }
            }
            startNum++;
        }
        return list;
    }
}
